
ifeq ($(PARAM_FILE), )
	PARAM_FILE:=../../../Makefile.param
	include $(PARAM_FILE)
endif
ifeq ($(COMP_PARAM_FILE), )
    COMP_PARAM_FILE:=../../../Makefile.param
    include $(COMP_PARAM_FILE)
endif

PANEL_PATH := $(PANEL_ROOT)/panel
LIB_PATH = $(PANEL_PATH)/user/lib
OBJ_PATH = $(PANEL_PATH)/user/src/obj

PANEL_INC := -I$(PANEL_PATH)/user/include\
	-I$(COMM_INC)\

SRC_DIR := $(PANEL_PATH)/user/src

CFLAGS += -Wall -fPIC

ifeq ($(EIGDB),EI_GDB)
CFLAGS += -g
endif

CFLAGS  += -O2
CFLAGS  += $(LIBS_CFLAGS)
DFLAGS  := -DEXT_REG
DFLAGS  += $(MEDIA_FLAGS)

DEPEND_FILE := $(foreach file,$(subst -I, ,$(PANEL_INC)), $(wildcard $(file)/*.h))
SRCS_TMP := $(foreach file,$(subst -S, ,$(SRC_DIR)), $(notdir $(wildcard $(file)/*.c)))
SRCS = $(SRCS_TMP)

OBJS := $(SRCS:%.c=$(OBJ_PATH)/%.o)
VPATH = $(subst -S, ,$(SRC_DIR))

COMPILE = $(CC) $(CFLAGS) $(DFLAGS) $(PANEL_INC) -lm

$(warning $(PARAM_FILE))
$(warning $(COMP_PARAM_FILE))
$(warning $(LIBS_LD_CFLAGS))

$(OBJ_PATH)/%.o : %.c $(DEPEND_FILE)
	@(echo "compiling $< ...")
	@[ -e $(LIB_PATH) ] || mkdir -p $(LIB_PATH)
	@[ -e $(OBJ_PATH) ] || mkdir -p $(OBJ_PATH)
	@($(COMPILE) -o $@ -c $<)

all:$(OBJS)
	@for x in `find ./ -maxdepth 2 -mindepth 2 -name "Makefile" `; \
	   do cd `dirname $$x`; if [ $$? ]; then make || exit 1; cd ../; fi; done

clean:
	@for x in `find ./ -maxdepth 2 -mindepth 2 -name "Makefile" `; \
   do cd `dirname $$x`; if [ $$? ]; then make clean; cd ../; fi; done
